function f = function_transform_2d(V1, u, V2)

if size(V1) ~= size(V2)
    error("V1 and V2 should have the same size.");
end

switch size(V1,1)
    case 3
        A = zeros(3,3);
        for i = 1:size(V2,1)
            A(i,1) = 1;
            A(i,2) = V2(i,1);
            A(i,3) = V2(i,2);
        end
        b1 = V1(:,1);
        b2 = V1(:,2);
        X = A\b1;
        Y = A\b2;
        trans_x = @(xi,eta) X(1)+X(2)*xi+X(3)*eta;
        trans_y = @(xi,eta) Y(1)+Y(2)*xi+Y(3)*eta;
    case 4
        A = zeros(4,4);
        for i = 1:size(V2,1)
            A(i,1) = 1;
            A(i,2) = V2(i,1);
            A(i,3) = V2(i,2);
            A(i,4) = V2(i,1)*V2(i,2);
        end
        b1 = V1(:,1);
        b2 = V1(:,2);
        X = A\b1;
        Y = A\b2;
        trans_x = @(xi,eta) X(1)+X(2)*xi+X(3)*eta+X(4)*xi.*eta;
        trans_y = @(xi,eta) Y(1)+Y(2)*xi+Y(3)*eta+Y(4)*xi.*eta;

    otherwise
        error("Invalid V1 and V2.");
end

if iscell(u)
    f = cellfun(@(f) @(xi,eta) f(trans_x(xi,eta), trans_y(xi,eta)), u, 'UniformOutput', false);
elseif isa(u, "function_handle")
    f = @(xi,eta) u(trans_x(xi,eta), trans_y(xi,eta));
elseif isnumeric(u)
    f = 0;
end

end